<?php
require_once("LoginHandler.php");
class RemoveView{
	private $removebuttonValue = "Remove";
	private $removebuttonArray = array();
	
	const CANNOT_REMOVE_USER = 1;
	//Skapar en tabell med medlemmar att ta bort.
	public function RemoveList($userarray){
		$retlist = "";
		$removeuserstring = "<h3>Choose a user to remove!</h3>";
		
		$retlist .= "<form method=\"post\"><table>";
		
		foreach($userarray as $user){
			if($user->getUsername() != $_SESSION[LoginHandler::USERSESSION])
			{
				$retlist .= "<tr><td>";
				$retlist .= $user->getId();
				$retlist .= "</td><td>";
				$retlist .= $user->getUsername();
				$retlist .= "</td><td>";
				$retlist .= "<input type=\"submit\" value=" . $this->removebuttonValue . " name=" . $user->getId() ." />";
				$retlist .= "</td></tr>";
			}
		}
		
		$retlist .= "</table></form>";
		return $removeuserstring . $retlist;
	}
	//Undersöker om man har klickat på "ta bort medlem" på en specifik medlem.
	public function GetRemoveClick(User $user){
		if(isset($_POST[$user->getId()]) && $_POST[$user->getId()] == $this->removebuttonValue){
			return true;
		}
		return false;
		
	}
	//Används för att skriva ut felmeddelanden
	public function Messages($index){
		switch ($index) {
			case self::CANNOT_REMOVE_USER:
				return "Can't remove this user";
				break;
			default:
				return "Error! This message is not set!";
				break;
		}
	}
	
	
	

}
?>